{# SPDX-FileCopyrightText: © 2015 Siemens AG

   SPDX-License-Identifier: FSFAP
#}

function createDirlistTable() {
  var dirlistTableConfig = {
    "bServerSide": true,
    "sAjaxSource": "?mod=ajax_file_browser",
    "fnServerData": function (sSource, aoData, fnCallback) {
      aoData.push({"name": "upload", "value": {{ uploadId }} });
      aoData.push({"name": "item", "value": {{ itemId }} });
      aoData.push({"name": "totalRecords", "value": {{ iTotalRecords }} });
      aoData.push({"name": "agentId", "value": {{ agentId|default(0) }} });
      aoData.push({"name": "scanFilter", "value": $('#scanFilter').val() });
      {% if isFlat %}aoData.push({"name": "flatten", "value": "yes" });{% endif %}
      $.getJSON(sSource, aoData, fnCallback)
        .fail(failed)
    },
    "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
        if (nRow.className.match(/(^| )removed($| )/g)  ) {
            $('td', nRow).addClass('read_only');
        }
    },
    "aoColumns": [{"sTitle":"Files","sClass":"left"},
        {"sTitle":"Scanner Results&nbsp;{{ agent_list }}","sClass":"left","bSortable":false},
        {"sTitle":"Actions","sClass":"left","bSortable":false,"bSearchable":false}],
    "sPaginationType": "listbox",
    "iDisplayLength": 25,
    "bProcessing": true,
    "bStateSave": true,
    "bRetrieve": true,
    "bPaginate": true,
    "bFilter": true,
    "bAutoWidth": true,
    "iDisplayLength":50,
    "oLanguage":{"sInfo":"Showing _START_ to _END_ of _TOTAL_ files" ,
      "sSearch":'_INPUT_<button class="btn btn-default btn-sm" onclick="clearSearchFiles();" title=\"{{ 'Clear file filter'|trans }}\" >Clear<\/button>',
      "sLengthMenu":'Display <select class="form-control-sm"><option value="10">10<\/option><option value="25">25<\/option><option value="50">50<\/option><option value="100">100<\/option><\/select> {#
       #}   {{ 'files'|trans }} ({% if isFlat %}<a href="{{ fileSwitch }}">{{ 'tree view'|trans }}</a> {{ 'or'|trans }} <b>{{ 'flat'|trans }}</b>{#
       #}{% else %}<b>{{ 'tree view'|trans }}</b> {{ 'or'|trans }} <a href="{{ fileSwitch }}">{{ 'flat'|trans }}</a>{% endif %})'
      }
  };

  otable = $('#dirlist').dataTable(dirlistTableConfig);
}

$(document).ready(function () {
  createDirlistTable();
  $('img').tooltip();
  $("#lichistogram_length select").css('text-align','right');
  $("#dirlist_length select").css('text-align','right');
});

